package controller.webutil;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import core.base.controller.BaseSpringController;
import core.util.ParamUtil;
import core.util.codec.Codec;

@Controller("controller.webutil.CodecController")
@RequestMapping("/webutil")
public class WebutilController extends BaseSpringController {
	
	@RequestMapping("codec.htm")
	public ModelAndView codec(HttpServletRequest request, HttpServletResponse response) {
		int originalStrCount = ParamUtil.getInt(request,"count",0);
		StringBuffer codeBuf = new StringBuffer("count="+originalStrCount);
		for (int i = 0; i < originalStrCount; i++) {
			String codec = Codec.encode(ParamUtil.getString(request, "str"+i, ""), "UTF-8");
			codeBuf.append("&str").append(i).append("=").append(codec);
		}
		try {
			response.getWriter().write(codeBuf.toString());
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}
}
